var alert = require('{layer}/alert');
var layer=require('{pub}layer');
var util = require('util');
function checked(e, elem, data){/*或者复选框的值*/
    var mainObj = this;
    var main = mainObj.element;
    var checked = main.find('.table-tbody .table-row [type="checkbox"]:checked');
    
    if(!checked.length){
        alert('<p class="f-tac">请勾选需要操作的行</p>')
        return false;
    }else{
        var data = {
            list:[]
        };
        var dataname = checked.last().attr('name');
        datanamelist = [];
        checked.each(function(){
            //eval('debugger')
            var ele = $(this);
            if(ele.hasClass('all')){return;}
            datanamelist.push(ele.val());
            data.list.push(ele.closest('tr').data())
        })
        data[dataname] = datanamelist.join(',');
        return data;
    }
}
function getData(e, elem, data){/*a获取行data*/
    return elem.closest('tr').data();
}
function init(){/*main头部初始化组件*/
    var main = this.element,that=this;
    main.find('.u-select').imitSelect({
        callback:function(e,i){
            if(typeof i != 'undefined'){
                that.query();            
            }
        }
    });
    
    main.find('.checks').checkradio();
}
function submitback(res){/*首页操作之后的返回刷新或者关闭弹出层操作*/
    var mainObj = this;
    if(res.status =='1'){
        layer.hint('success',res.message);
        //self && self.hide();
        mainObj.paging.query(true);
    }else{
       // message('error',res.message)
        return false;
    } 
}
function query(){/*公用的main查询方法*/
    var that = this;
    var main = that.element;
    that.paging.condition = util.getData(main.find('.c-header')).result;
    that.paging.query(true);
}
module.exports={
    checked:checked,
    getData:getData,
    init:init,
    submitback:submitback,
    query:query
}